home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 July: Mac OS SDK / Dev.CD Jul 97 SDK2.toast / Development Kits (Disc 2) / ScriptX / Code Samples / untested / tcpip / browser / demo.sx < prev    next >
Encoding:
Text File  |  1996-05-21  |  1.9 KB  |  78 lines  |  [TEXT/ttxt]

  1. ---<<<
  2.  
  3. in module WebBrowser
  4.  
  5. -- Simple code that downloads an ascii file listing the available
  6. -- title containers. This list is displayed in a window. Clicking on a name
  7. -- downloads and opens the title container.
  8.  
  9. function fetchContainer data button -> (
  10.     button.enabled := false
  11.     openContainerFromURL data
  12.     button.enabled := true
  13. )    
  14.  
  15. function parseIndex stream -> (
  16.     local d := new Array
  17.     repeat until (isPastEnd stream) do (
  18.         append d #((getline stream), (getline stream))
  19.     )
  20.     d
  21. )
  22.  
  23. function getIndex url -> (
  24.     local p := geturl WebAccessManager url
  25.     parseIndex p[2]
  26. )
  27.  
  28. function showIndex url -> (
  29.     local idx := getIndex url
  30.     local window := new window
  31.     local y := 50
  32.     local x := 5
  33.     local bc := new actuatorcontroller space: window
  34.     bc.wholespace := true
  35.     local th := new textpresenter boundary: (new Rect x2: 300 y2: y)\
  36.             target: url
  37.     th.y := 20
  38.     -- setdefaultattr th @size 16
  39.     -- setdefaultattr th @weight @bold
  40.     prepend window th
  41.     for  i in idx do (
  42.         local description := i[1]
  43.         local url := i[2]
  44.         local tp1 := new TextPresenter target: description \
  45.                   boundary: (new Rect x2: 200 y2: 20)
  46.         local tp2 := new TextPresenter target: description \
  47.                   stroke: blackbrush \
  48.                   boundary: (new Rect x2: 200 y2: 20)
  49.     
  50.         local tp3 := new TextPresenter target: "Downloading.." \
  51.                   stroke: (new brush color: redcolor) \
  52.                   fill: whitebrush \
  53.                   boundary: (new Rect x2: 200 y2: 20)
  54.     
  55.         local pb := new PushButton \
  56.                 releasedPresenter: tp1 \
  57.                 pressedPresenter: tp2 \
  58.                 disabledPresenter: tp3
  59.         pb.x := x
  60.         pb.y := y
  61.         prepend window pb
  62.         pb.activateAction := fetchContainer
  63.         pb.authorData := url;
  64.         y := y + 20
  65.     )
  66.     show window
  67. )
  68.  
  69. function timedownload url -> (
  70.     local startTime := theeventtimestampclock.time
  71.     local headers := (getURLToTempFile WebAccessManager url)[1]
  72.     local endtime := theeventtimestampclock.time
  73.     local size := headers["content-length" as string]
  74.     (size as float) /  ((endtime - starttime) as integer) * starttime.scale
  75. )
  76.  
  77. -->>
  78.